<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$item=$this->plugin_setting('setting');
if($_RQ['op']=='main'){
	$id=$_RQ['id'];
	$his=pdo_get('jy_cmslive_his',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
	if($his){
		pdo_update('jy_cmslive_his',array('time'=>time()),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
	}else{
		pdo_insert('jy_cmslive_his',array('time'=>time(),'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
	}
	
	$signs=pdo_get('jy_cmslive_sign',array('uid'=>$_SESSION['uid']));
	$sign=$signs['sign'];
	$avatar=pdo_getcolumn('core_fans',array('mid'=>$_SESSION['uid']),'avatar');
	if(strlen($sign)<10){
		pdo_delete('jy_cmslive_sign',array('uid'=>$_SESSION['uid']));
		$identifier=random(5);
		$adminkey=$item['adminkey'];
		$sign=$this->getusersig($identifier, $item['appid'], $adminkey);
						
		if(strlen($sign)>10){
			pdo_insert('jy_cmslive_sign',array('uniacid'=>$_SESSION['uniacid'],'uid'=>$_SESSION['uid'],'name'=>$identifier,'createtime'=>TIMESTAMP,'sign'=>$sign));
		}else{
			exi('生成用户签名失败，请检查云服务设置是否正确','error');
		}
	}
	
	
	if(!id){
		exi('请先选择直播间','error');
	}
	$room=pdo_get('jy_cmslive_list',array('id'=>$id));
	$room['time']=$v['time']?date('Y-m-d H:i:s',$room['time']):'';	
	$room['menu']=json_decode($room['menu'],true);
	$info=$this->getLiveInfo($room['url']);		
	if($info['status']!=1){
		//exi('暂未开播,请注意直播开始时间','error','/index/');
	}
	//$info = array('status' => $apiResult['isPlay'], 'poster' => $apiResult['videoCoverUrl'], 'hls_url' => $apiResult['hlsVideoUrl']);
	$return['info']=$info;
	$return['room']=$room;
	
	//$return['sign']=$sign;
	$return['signs']=$signs;
	$return['setting']=$item;
	exi($return);
	}
if($_RQ['op']=='dy'){
	$data=get_postdata();
	$id=$data['id'];
	$his=pdo_get('jy_cmslive_dy',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
	if($his){
		pdo_delete('jy_cmslive_dy',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
		exi('已取消订阅','error');
	}else{
		pdo_insert('jy_cmslive_dy',array('time'=>time(),'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'rid'=>$id));
		exi('订阅成功','error');
	}
}
?>